<template>
  <div class="container">
    <text class="big-title">示例</text>
    <div>
      <text class="text">{{defaultText}}</text>
      <div class="btn" @click="clip">
        <text class="text">复制上面的文本并粘贴到输入框</text>
      </div>
      <textarea rows="5" @focus="onFocus" :value="textareaValue" placeholder="获取焦点时自动粘贴"></textarea>
    </div>
    <text class="big-title">文档</text>
    <div class="button" @click="showDoc"><text class="btn-text">点击查看文档</text></div>
  </div>
</template>

<style scoped>
.container {
  padding: 10px;
}
.big-title {
  color: black;
  font-size: 50px;
  font-weight: bold;
  margin-bottom: 20px;
  margin-top: 20px;
}
.text {
  font-size: 30px;
}
.btn {
  border-width: 2px;
  border-color: black;
  border-radius: 8px;
  justify-content: center;
  align-items: center;
  padding-top: 20px;
  padding-bottom: 20px;
  background-color: transparent;
  margin-bottom: 20px;
  margin-top: 20px;
}
.btn:active {
  background-color: #ECECEC;
}
.button {
  height: 60px;
  justify-content: center;
  opacity: 1.0;
}
.button:active {
  opacity: 0.6;
}
.btn-text {
  font-size: 30px;
  color: blue;
}
</style>

<script>
  import utils from '../utils.js';
  let clipboard = weex.requireModule('clipboard');
  let modal = weex.requireModule('modal');
  let navigator = weex.requireModule('navigator');
  export default {
    data: {
      defaultText: '点击下面的按钮复制这段文本，然后点击输入框即可自动粘贴文本。',
      textareaValue: ''
    },
    methods: {
      clip() {
        clipboard.setString(this.defaultText);
        modal.toast({
          message: '文本已复制！',
          duration: 1
        })
      },
      onFocus() {
        clipboard.getString((res) => {
          this.textareaValue = '从剪切板中获取的数据为：\n' + res.data
        })
      },
      showDoc() {
        navigator.push({
          url: utils.getDocDetailUrl(weex.config.bundleUrl),
          animated: true
        });
      }
    }
  }
</script>
